import os
import hou


def scene_was_loaded():
    current_path=hou.getenv('HIP')
    job_path=os.path.split(current_path)[0]#+'HAHA'
    # job_path='C:/timeaxis'
    hou.putenv('JOB',job_path)

scene_was_loaded()

def createProjectSetting():
    root=hou.node("/obj")
    root.createNode("project_setting",'Project_Setting')

#createProjectSetting()

def createNetworkBox():
    root=hou.node("/obj")
    items=root.allItems()
    networkbox_list=['Asset','Ani_Edit','FX','Render']
    sort_key={'Asset':1,'Ani_Edit':2,'FX':3,'Render':4}
    has_list=[]
    for i in items:
        if i.name() in networkbox_list:
            has_list.append(i.name())

    set_a = set(networkbox_list)
    set_b = set(has_list)
    delta=set_a^set_b
    delta_list=sorted(list(delta),key=lambda x : sort_key[x])

    posx=0
    for n in delta_list:
        net_box=root.createNetworkBox(n)
        net_box.setSize(hou.Vector2(10,15))
        net_box.setComment(n)
        net_box.setPosition(hou.Vector2(posx*12+3,2))
        posx+=1

def createProjectSetting():
    root=hou.node("/obj")
    items=root.allItems()
    projectNode=None
    for i in items:
        if i.name()=='Project_Setting':
            projectNode=i

    if not projectNode:
        projectNode=root.createNode('project_setting','Project_Setting')
    projectNode.setPosition(hou.Vector2(26.22,21.75))

createNetworkBox()
createProjectSetting()
